package tests;

import common.Utils;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;

public class EditPage extends Utils {
    private static String url = "http://120.26.87.94:8080/blog_edit.html";
    public EditPage() {
        super(url);
    }

    public void EditSuc() throws InterruptedException {
        Thread.sleep(2000);

        String blogTitle = "Edit Test";

        driver.findElement(By.cssSelector("#title")).sendKeys(blogTitle);

        driver.findElement(By.cssSelector("#submit")).click();

        Thread.sleep(2000);
        String title = driver.getTitle();
        System.out.println(title);



        assert title.equals("博客列表页");
//        WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(2));
//        wait.until(ExpectedConditions.presenceOfElementLocated());

        //无法输入博客内容---怎么办？
        //两个解决办法：
        //1）博客内容本身就有默认内容，我们不需要手动实现
        //2）通过键盘操作来实现
//        WebElement ele = driver.findElement(By.cssSelector("#editor > div.CodeMirror.cm-s-default.CodeMirror-wrap > div.CodeMirror-scroll > div.CodeMirror-sizer > div > div > div > div.CodeMirror-code > div > pre"));
//
//        Actions actions = new Actions(driver);
//        Thread.sleep(2000);
//        actions.doubleClick(ele).perform();
//        Thread.sleep(2000);
//        actions.keyDown(Keys.DELETE).perform();
//        Thread.sleep(2000);
//        actions.moveToElement(ele).sendKeys("输入文本").perform();

        driver.quit();
    }
}
